package lambda.function;
import lambda.entity.Child1;
import lambda.entity.Child2;
import lambda.entity.User;
import java.util.function.Supplier;

/**
 * @author LIBOFEI
 * @ClassName SupplierTest
 * @description Supplier 供给型接口 提供 T 类型的对象
 * @date 2022/4/6 17:04
 * @Version 1.0
 **/
public class SupplierTest {

    public static void main(String[] args) {
        //未使用lamda之前
        printUser(new Supplier<User>() {
            @Override
            public User get() {
                return getChild1();
            }
        });
        //使用之后
        printUser(() -> getChild2());
        printUser(SupplierTest::getChild2);
    }

    public static User getChild1(){
        Child1 child1 = new Child1();
        child1.setId(1);
        child1.setName("李博飞");
        return child1;
    }

    public static User getChild2(){
        Child2 child1 = new Child2();
        child1.setId(2);
        child1.setName("ssss");
        return child1;
    }

    public static void printUser(Supplier<User> supplier){
        User user = supplier.get();
        System.out.println(user.getName());
    }
}
